//
//  NSDate+Extend.m
//  GroupBuy
//
//  Created by wwj on 15/11/16.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "NSDate+Extend.h"

@implementation NSDate (Extend)
+ (NSDateComponents *)compareFrom:(NSDate *)from to:(NSDate *)to{
    // 1.日历对象（标识：时区相关的标识）
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    // 2.合并标记
    NSUInteger flags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    
    // 3.比较
    return [calendar components:flags fromDate:from toDate:to options:0];
}

- (NSDateComponents *)compare:(NSDate *)other{
    return [NSDate compareFrom:self to:other];
}
@end
